<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>

<c:choose>
	<c:when test="${param.actionSerial == 0 }"><!-- 第一次加载首页面获取的数据 -->
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where
				    t.f_draft = 1 and ( t.f_creator_id=${me.id } or t.f_blog_id in 
				    (select f_blog_id from t_blog_mark where f_marker_id =${me.id}) or t.f_blog_id in (select f_id from t_blog where 
				    f_type = 'public'))
				    order by t.f_id desc limit 0,10"
				id="articles" />
	</c:when>
	<c:when test="${param.actionSerial == 1 }"><!-- 获取首页更多条数据 -->
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where ( t.f_creator_id=${me.id } or t.f_blog_id in 
				    (select f_blog_id from t_blog_mark where f_marker_id =${me.id}) or t.f_blog_id in (select f_id from t_blog where 
				    f_type = 'public')) and 
				    f_draft = 1  and t.f_id < ${param.lastArticleId }    order by t.f_id desc limit 0,${param.count }"
				id="articles" />
	</c:when>
	
	 
	
	<c:when test="${param.actionSerial == 2 }"><!--第一次xx博客的博文 -->
		<nativeSql:sqlQueryForList
				sql="select t.*,a.f_username from t_article t left join app_user a on t.f_creator_id = a.f_id where 
				   t.f_blog_id = ${param.blogId }  order by t.f_id desc limit 0,6 "
				id="articles" />
	</c:when>
	 <c:when test="${param.actionSerial == 3 }"><!--获取xx博客更多文章数据  -->
		<nativeSql:sqlQueryForList
				sql="select t.*,a.f_username from t_article t left join app_user a on t.f_creator_id = a.f_id  where 
				   t.f_id < ${param.lastArticleId } and t.f_blog_id = ${param.blogId } order by t.f_id desc limit 0,${param.count } "
				id="articles" />
	</c:when>
	
	
	
	<c:when test="${param.actionSerial == 6 }"><!--第一次获取我收藏的博文 -->
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where 
				   t.f_id  in (select f_article_id from t_article_mark  where f_marker_id = ${param.userId })  order by t.f_id desc limit 0,6 "
				id="articles" />
	</c:when>
    <c:when test="${param.actionSerial == 7 }"><!-- 获取我收藏的博文 更多数据  -->
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where
				  t.f_id < ${param.lastArticleId }  and t.f_id  in (select f_article_id from t_article_mark  where f_marker_id = ${param.userId }) order by t.f_id desc limit 0,${param.count } "
				id="articles" />
	</c:when>


    
    <c:when test="${param.actionSerial == 4 }"><!--第一次获取我发布的博文 -->
    	<c:if test="${me.id!=param.userId }">
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where 
				       t.f_creator_id  = ${param.userId } and t.f_draft=1 and t.f_blog_id in 
				       (select f_id from t_blog where f_if_personal='1')
				       order by t.f_id desc limit 0,6 "
				id="articles" /></c:if>
		<c:if test="${me.id==param.userId}">
			<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where 
				       t.f_creator_id  = ${param.userId } and t.f_draft=1 
				       order by t.f_id desc limit 0,6 "
				id="articles" />
		</c:if>
				
	</c:when>
    <c:when test="${param.actionSerial == 5 }"><!-- 获取我发布的博文更多数据  -->
    	<c:if test="${me.id!=param.userId }">
		<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where t.f_draft=1 and t.f_blog_id in 
				       (select f_id from t_blog where f_if_personal='1') and 
				   t.f_creator_id  = ${param.userId }  and t.f_id < ${param.lastArticleId }  order by t.f_id desc limit 0,${param.count } "
				id="articles" />
		</c:if>
		<c:if test="${me.id==param.userId}">
			<nativeSql:sqlQueryForList
				sql="select t.* from t_article t where 
				       t.f_creator_id  = ${param.userId } and t.f_draft=1 and t.f_id < ${param.lastArticleId }
				       order by t.f_id desc limit 0,${param.count } "
				id="articles" />
		</c:if>
				
	</c:when>
	
	
	<c:when test="${param.actionSerial == 8 }"><!--第一次获取我回复的博文 -->
		<nativeSql:sqlQueryForList
				sql="select t.*,a.f_username from t_article t left join app_user a on t.f_creator_id = a.f_id where 
				     t.f_id  in (select f_article_id from t_article_comment  where f_creator_id = ${param.userId })  order by t.f_id desc limit 0,6  "
				id="articles" />
	</c:when>
    <c:when test="${param.actionSerial == 9 }"><!-- 获取我回复的博文更多数据  -->
		<nativeSql:sqlQueryForList
				sql="select t.*,a.f_username from t_article t left join app_user a on t.f_creator_id = a.f_id where 
				     t.f_id  in (select f_article_id from t_article_comment  where f_creator_id = ${param.userId })   and t.f_id < ${param.lastArticleId }  order by t.f_id desc limit 0,${param.count } "
				id="articles" />
	</c:when>
	
	

</c:choose>

	<c:forEach items="${articles }" var="article">
					<div class="feed-photo" data-articleId="${article.f_id }">
						<!-- 头像的设置 -->
						<div class="feed-avatar">
							<nativeSql:sqlQueryForUnique
								sql="select f_picture_appended as avatarId from app_user  where f_id = ${article.f_creator_id } "
								id="avatar" />
							
							
							<img alt="头像"  class="blog-avatar"   <c:if test="${ article.f_creator_id == me.id}">data-from="me"</c:if> 
							  rel="${ctx }/widgets/avatarInfo.jsp?userId=${article.f_creator_id }"    title="${article.f_creator_name }" 
							  src="${ctx}/user/file.action?method:previewPic&fileId=${avatar.avatarId }">
						</div>


						<nativeSql:sqlQueryForUnique
							sql="select count(*) as cnt from t_article_mark where f_article_id =${article.f_id } and f_marker_id = ${me.id }"
							id="marksCnt" />
						<c:if test="${marksCnt.cnt == 0 }">
							<img src="${ctx }/img/star_off.gif" class="mark-star"
								data-status="0" data-articleId="${article.f_id }"></img>
						</c:if>
						<c:if test="${marksCnt.cnt > 0 }">
							<img src="${ctx }/img/star_on.gif" class="mark-star"
								data-status="1" data-articleId="${article.f_id }"></img>
						</c:if>

						<div class="pop-content">
							<div class="nupt-line-top"></div>
							<div class="feed-bd no-hd-content"
								style="background-color: rgb(255, 255, 255); padding: 5px 5px 20px 5px;">
								<nativeSql:sqlQueryForUnique sql="select f_blog_name as blogName FROM t_blog  where  f_id =${article.f_blog_id }"  id="blogName"/>
								<div  class="article-title">
								   <span  style="float: right;padding-right: 18px;font-size: 12px;font-style: italic;color: rgba(26, 17, 17, 0.6);">
								     <a href="${ctx }/blog/blogIndex.jsp?blogId=${article.f_blog_id }"  target="_blank"> ${blogName.blogName }</a>
								   </span>
								   <a href="${ctx }/blog/blog.action?method:article=xxx&articleId=${article.f_id }" target="_blank" title="查看完整博文">${article.f_title } </a></div>
								<div class="feed-ct">
                                   <!-- 分享音乐的显示 -->
                                   <nativeSql:sqlQueryForList
												sql="select * from t_media t  where  f_type = 1 and f_article_id =  ${article.f_id }"
												id="musics" />
                                   <c:forEach  items="${musics }"  var="music">
                                   <div>
                                       <Strong  style="float: left;padding-top: 8px;">${music.f_title}:</Strong>
                                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${music.f_html_code}
                                   </div>
                                   </c:forEach>
                                   <!-- 分享视频的显示 -->
                                   <nativeSql:sqlQueryForList
												sql="select * from t_media t  where  f_type = 2 and f_article_id =  ${article.f_id }"
												id="videos" />
                                   <c:forEach  items="${videos }"  var="video">
                                   <div >
                                                                                                                              分享视频：<Strong>${video.f_title }</Strong><br>
                                       ${video.f_html_code}
                                   </div>
                                   </c:forEach>
                                   <!-- 关于图片的显示问题 -->
									<div class="feed-img-all post-one-img no-title ">
										<div class="feed-big-img">
											<!-- 关于多幅图片布局问题设计 -->
											<nativeSql:sqlQueryForList
												sql="select  *  from t_upload_file where f_article_id = ${article.f_id }"
												id="articlefiles" />
											<nativeSql:sqlQueryForUnique
												sql="select  count(*) as cnt  from t_upload_file where f_article_id = ${article.f_id }"
												id="articlefilesCnt" />

											<c:forEach items="${articlefiles }" var="articlefile"
												varStatus="index">
												<c:if test="${articlefilesCnt.cnt >4 }">
													<img class="feed-img-4-${ index.count % 4}"
														src="${ctx}/user/file.action?method:previewPic&fileId=${articlefile.f_id}">
													<c:set value="${articlefilesCnt.cnt -1 }"
														var="articlefilesCnt.cnt"></c:set>
												</c:if>
												<c:if test="${articlefilesCnt.cnt <=4 }">
													<img
														class="feed-img-${articlefilesCnt.cnt }-${ index.count % 4}"
														src="${ctx}/user/file.action?method:previewPic&fileId=${articlefile.f_id}">
												</c:if>
											</c:forEach>

										</div>
										<div class="feed-img-too-high-tip" style="width: 650px"></div>
									</div>

									<div class="feed-img-desc rich-content">
										<yn:cleanHtml str="${article.f_content }" id="articleNoHtml"/>
					                    <yn:shortIt len="150" str="${articleNoHtml}" id="articleText"/>
									   <p>${articleText }</p>
									
									</div>
								
								</div>
							<div class="feed-act">
	
  <!-- 添加顶和踩的功能 -->									
  <hql:queryForUnique hql="from TopStep where articleId = ${article.f_id} and username='${me.username}' " id="visit"/>
  <nativeSql:sqlQueryForUnique sql="select count(*) as Num from t_top_step where f_article_id = ${article.f_id} and f_action ='top' " id="topNum"/>
  <nativeSql:sqlQueryForUnique sql="select count(*) as Num from t_top_step where f_article_id = ${article.f_id} and f_action ='step' " id="stepNum"/>
  
  <div  style="float: left;">
  	<c:if test="${not empty visit || article.f_creator_id == me.id}">
  	<span style="color: red;"><strong><c:if test="${empty topNum.Num }">0</c:if>${topNum.Num}</strong>&nbsp;&nbsp;&nbsp;顶&nbsp;&nbsp;</span>|
  	<span style="color:rgb(21, 80, 233);"><strong><c:if test="${empty stepNum.Num }">0</c:if>${stepNum.Num}</strong>&nbsp;&nbsp;&nbsp;踩&nbsp;&nbsp;</span>
  	</c:if>
  	
  	<c:if test="${empty visit && article.f_creator_id != me.id}">
  	<div id="show-${article.f_id}">
  	<a href='javascript:void(0);'  onclick='digg("${me.username}","${article.f_id}", "${topNum.Num}","${stepNum.Num}",false);return false;'>
  	       <strong><c:if test="${empty topNum.Num }">0</c:if>${topNum.Num}</strong>&nbsp;&nbsp;&nbsp;顶&nbsp;&nbsp;</a>|
    <a href='javascript:void(0);'  onclick='digg("${me.username}","${article.f_id}","${topNum.Num}","${stepNum.Num}", true);return false;'>
           <strong><c:if test="${empty stepNum.Num }">0</c:if>${stepNum.Num}</strong>&nbsp;&nbsp;&nbsp;踩&nbsp;&nbsp;</a>
   	</div>
   	<div id="hidden-${article.f_id}"  style="display:none;"></div>
    </c:if>
  </div>
<!--   显示标签 -->
<c:if test="${article.f_tags!=null }">

		<span class="showTags">   
		<nativeSql:sqlQueryForList sql="select  *  from t_tag_mark where f_relate_entity_id = ${article.f_id }" id="tags" />
		 <c:forEach  items="${tags }"  var="tag">
		<span><a href="${ctx}/blog/blog.action?method:articleTag&tag=${tag.f_tag_Name}"> <span class="opti">${tag.f_tag_Name}</span></a></span>
		</c:forEach>
		</span>							
</c:if>
									<a class="feed-cmt" data-status="0"
										data-articleid="${article.f_id }">回应</a>
									
									<a class="feed-pre" title="查看该条博文全部内容"  target="_blank" href="${ctx }/blog/blog.action?method:article&articleId=${article.f_id}"
									   data-href="${ctx }/blog/article.jsp?articleId=${article.f_id}&nid=<%=(System.currentTimeMillis())%>&title=${article.f_title}">查看</a>
									
									
									<c:if test="${me.id == article.f_creator_id || role == 'manager'}">
									
									<a class="feed-del" data-articleid="${article.f_id }">删除</a>
                                    <a href="${ctx }/blog/blog.action?method:articleEditForm&articleId=${article.f_id}"
										class="feed-edit"
										data-href="${ctx }/blog/articleEditForm.jsp?articleId=${article.f_id}&nid=<%=(System.currentTimeMillis())%>&title=${article.f_title}">编辑</a>
									</c:if>
								</div>

							</div>
							<div class="nupt-line-buttom"></div>

							<!-- 回复部分的内容 -->
							<div class="feed-com" data-nid="feed-com-${article.f_id }"
								style="display: none;">
								<div class="feed-ft-triangle"></div>
								<input type="text" title="提醒：ctrl+enter提交"
									data-nid="${article.f_id }" class="feed-comment-input"
									onkeyup="javascript:return ctrlEnter(this,event);"></input>
								<div data-nid="feed-rep-content-${article.f_id }"></div>
								<nativeSql:sqlQueryForUnique
			                         sql="select count(*) as CommentsNum from t_article_comment  where f_article_id = ${article.f_id }"  id="CommentsNum" />
								    <!-- 每次只显示3条数据，如果大于3条数据的话，则显示获取更多回复的按钮 -->
                                   
                                   <c:if test="${CommentsNum.CommentsNum > 3 }">    
                                        <input type="button"  data-articleId="${article.f_id  }"  data-current-numbers="3"  class="feed-rep-more-button" value="获取更多回复"></input>  
                                  </c:if>
   
							</div>

						</div>
						<!-- POP END -->
						<div style="clear: both;"></div>
					</div>

				</c:forEach>